%% Nankai University Bachelor Thesis Template
%% Zhang Zhuo Yu <zhangzhuoyu@mail.nankai.edu.cn>
\ProvidesPackage{nkbishe}[20200128]
\RequirePackage{ifthen}

\newboolean{isnkdraft}
\DeclareOption{nkdraft}{
\setboolean{isnkdraft}{true}
}
\DeclareOption{nkpublish}{
\setboolean{isnkdraft}{false}
}
\ExecuteOptions{nkdraft}
\ProcessOptions\relax

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Times New Roman}
\usepackage{refstyle}
\usepackage{setspace}
\usepackage{esint}
\onehalfspacing
\ifthenelse{\boolean{isnkdraft}}{
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}
 \usepackage[demo]{graphicx}
}{
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]
 {hyperref}
 \usepackage{graphicx}
}

\usepackage{calc}
\usepackage{geometry}
\ifthenelse{\boolean{isnkdraft}}{
\geometry{a4paper, showframe,top=2.54cm,bottom=2.54cm,inner=3.17cm,outer=3.17cm,headsep=2.54cm-1.5cm-\headheight, footskip=2.54cm-1.75cm}
}{
\geometry{a4paper, top=2.54cm,bottom=2.54cm,inner=3.17cm,outer=3.17cm,headsep=2.54cm-1.5cm-\headheight, footskip=2.54cm-1.75cm}
}
\usepackage{fancyhdr}
\usepackage{abstract}
\setlength{\absleftindent}{0mm}
\setlength{\absrightindent}{0mm}
\usepackage{layout}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage[toc,page,title,header]{appendix}
\usepackage{newtxmath}
\usepackage[perpage]{footmisc}


\usepackage[UTF8,heading,cap,cs4size,linespread=1.5]{ctex}
\ctexset{
punct=quanjiao,
autoindent=true,
contentsname=\textbf{\zihao{3}目　录},
section = {
name={,、},
number = \chinese{section},
format = \centering\zihao{-3}\bfseries,
aftername={},
},
subsection = {
name={（,）},
number = \chinese{subsection},
format = \zihao{4}\bfseries,
aftername={},
},
subsubsection={
name={,.},
number=\arabic{subsubsection},
format = \zihao{-4}\bfseries,
aftername={\quad},
%tocline=\CTEXthesubsubsection~~#2,
}
}


\renewcommand{\appendixtocname}{附录}
\renewcommand{\appendixpagename}{\centering\textbf{\zihao{4}附　录}}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cfttoctitlefont}{\hfill}
\renewcommand{\cftdot}{\ensuremath{\cdot}}

\renewcommand{\cftsecfont}{\zihao{-3}\songti}
\renewcommand{\cftsecpagefont}{\zihao{-3}}
\renewcommand{\cftsecdotsep}{\cftdotsep}

\renewcommand{\cftsubsecfont}{\zihao{4}\songti}
\renewcommand{\cftsubsecpagefont}{\zihao{4}}
\renewcommand{\cftsubsecdotsep}{\cftdotsep}

\renewcommand{\cftsubsubsecfont}{\zihao{4}\songti}
\renewcommand{\cftsubsubsecpagefont}{\zihao{4}}
\setlength{\cftsubsubsecnumwidth}{1em}


\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
             \node[shape=circle,draw,inner sep=0pt] (char) {#1};}}
\renewcommand{\thefootnote}{\protect\circled{\arabic{footnote}}}
\newcommand{\cabstract}[2]{\renewcommand{\abstractname}{\textbf{\zihao{4}摘　要}}\thispagestyle{empty}\begin{abstract}\zihao{-4}\noindent　　#1\par\noindent\textbf{\zihao{-4}关键词：}{\zihao{-4}#2}\end{abstract}\newpage{}}
\newcommand{\eabstract}[2]{\renewcommand{\abstractname}{\textbf{\zihao{4}Abstract}}\thispagestyle{empty}\begin{abstract}\zihao{-4}\noindent　　#1\par\noindent\textbf{\zihao{-4}Keywords: }{\zihao{-4}#2}\end{abstract}\newpage{}}

\newcounter{ssec}
\let\tmpcmd\subsection
\renewcommand{\subsection}[1]{\tmpcmd{\refstepcounter{ssec}#1}}
\renewcommand{\thessec}{\CTEXthesection\CTEXthesubsection}

\newcounter{sssec}
\let\tmpcmdb\subsubsection
\renewcommand{\subsubsection}[1]{\tmpcmdb{\refstepcounter{sssec}#1}}
\renewcommand{\thesssec}{\CTEXthesection\CTEXthesubsection 之\arabic{subsubsection}}

\AtBeginDocument{%
\renewcommand{\secref}[1]{第\ref{sec:#1}节}%
\newcommand{\ssecref}[1]{第\ref{ssec:#1}节}%
\newcommand{\sssecref}[1]{第\ref{sssec:#1}节}%
\renewcommand{\eqref}[1]{式(\ref{eq:#1})}%
\renewcommand{\figref}[1]{图\,\ref{fig:#1}}%
}

\newcommand{\nkbiblio}{%
\newpage\pagestyle{plain}
{\raggedright\textbf{\zihao{4}参考文献}}\vskip 2.3ex plus .2ex
\refstepcounter{section}
\addcontentsline{toc}{section}{参考文献}%
}

\newenvironment{nkapp}{%
\newpage\section*{\centering\textbf{\zihao{4}附　录}}
\refstepcounter{section}
\addcontentsline{toc}{section}{附录}
\begin{subappendices}
\let\tmpCTEXthesubsection\CTEXthesubsection
\renewcommand{\CTEXthesubsection}{\Alph{subsection}}
\let\tmpthesubsection\thesubsection
\renewcommand{\thesubsection}{\Alph{subsection}}
\newcommand{\nkappitem}[1]{\subsection{##1}}
}{\end{subappendices}}

\newcommand{\nkzhixie}{%
\newpage\section*{\centering\textbf{\zihao{4}致　谢}}
\refstepcounter{section}
\addcontentsline{toc}{section}{致谢}%
}

\newcommand{\nksection}[1]{\newpage{}\section{#1}}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{1pt}
\let\tmpincgrphc\includegraphics
\renewcommand{\includegraphics}[2][]{\fbox{\tmpincgrphc[#1]{#2}}}

\pagestyle{fancy}
\cfoot{\thepage}
\rhead{}
\lhead{}
\renewcommand{\headrulewidth}{0pt}

\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage[subrefformat=parens]{subfig}

\usepackage{listings}
\usepackage[bibstyle=nkbib,citestyle=numeric-comp]{biblatex}

\tocloftpagestyle{empty}

\usepackage{keyval}

\endinput